package wang.API;

public class StringDemo {
    public static void main(String[] args) {
        //1获取字符串长度
        String s = "wang朝";
        System.out.println(s.length());

        //2.提取字符串中某个索引位置得字符
        char c = s.charAt(0);
        System.out.println(c);
        //字符串遍历
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            System.out.println(ch);
        }
        //3.把字符串转换成字符数组，在进行遍历
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            System.out.println(chars[i]);
        }
        //4。判断字符串内容 内容一样就返回true
        String s1 = "wang";
        String s2 = "wang";
        System.out.println(s1.equals(s2));

        //5.忽略大小写比较字符串内容
        String s3 = "wang";
        String s4 = "wanG";
        System.out.println(s3.equalsIgnoreCase(s4));
        //6 截取字符串内容 包前不包后
        String s5 = "wangzhaoyong";
        System.out.println(s5.substring(0,5));

        //7 从当前索引位置一直截取到末尾
        String s6 = "wangzhaoyong";
        System.out.println(s6.substring(5));

        //8将字符串内容替换成新内容 并返回新内容
        String info = "这个电影简直是个垃圾啊，垃圾电影";
        System.out.println(info.replace("垃圾", "**"));

        //9 判断字符串中是否包含某段关键字 包含返回true
        String s7 = "wangzhaoyong";
        System.out.println(s7.contains("wang"));

        //10 判断字符串是否以某个字符串开头 如果是 返回true

        String s8 = "wang";
        System.out.println(s8.startsWith("w"));

        //11 分割字符串 把字符串按照某个指定内容分割成多个字符串 把分割后得以字符串数组送给我们
            String s9 = "张三，李四，王五";
          String[] ch =  s9.split("，");
        for (int i = 0; i < ch.length; i++) {
            System.out.println(ch[i]);

        }
    }
    }
